<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @cancel="handleCancel"
    @ok="handleOk"
    cancelText="关闭">
    <div class="count" v-show="selectedRowKeys.length>0">
      <p>修改文件数：</p>
      <p class="rightPart">{{selectedRowKeys.length}}</p>
    </div>
    <a-spin :spinning="confirmLoading">
      <div class="dateChange">
        <p>请选择日期：</p>
        <a-date-picker class="rightPart" @change="onChange"/>
      </div>
    </a-spin>
    <!--    <doc-modal-check ref="modalForm" @ok="modalFormOk"></doc-modal-check>-->
  </a-modal>
</template>

<script>
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import JCategorySelect from '@/components/jeecg/JCategorySelect'
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JDate from '@/components/jeecg/JDate'
  import JDictSelectTag from '@/components/dict/JDictSelectTag'
  import JEditor from '@/components/jeecg/JEditor'
  import { queryDocHistoryById } from '@/api/api'
  import { getAction } from '@/api/manage'
  import DocModalCheck from './DocModalCheck'
  import DictDeleteList from '../../system/DictDeleteList'
  import { axios } from '../../../utils/request'
  import { putAction } from '../../../api/manage'
  import { frozenCategory } from '../../../api/api'

  export default {
    name: 'DateModal',
    components: {
      DictDeleteList,
      JDate,
      JDictSelectTag,
      JEditor,
      JCategorySelect,
      DocModalCheck
    },
    data () {
      return {
        temp:"",
        formData:{},
        form: this.$form.createForm(this),
        ids:[],
        title: '操作',
        width: 800,
        visible: false,
        model: {},
        time: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        selectedKeys: [],
        confirmLoading: false,
        dataSource: [],
        loading: false,
        url: {
          list: '/doc/doc/list',
          selectOne: '/doc/doc/selectOne',
          add: '/doc/doc/add',
          edit: '/doc/doc/edit',
          dateChange: '/doc/doc/dateChange',
          batchDateUpdate: 'doc/doc/batchDateUpdate'
        }
      }
    },
    props: {
      selectedRowKeys: {
        type: Array,
        default () {
          return []
        }
      }
    },
    methods: {
      batchEdit(id,operation){
        this.ids=[]
        for (let i = 0; i <id.length ; i++) {
         this.ids.push(id[i])
        }
        this.temp=operation
      },
      onChange (dateString) {
        this.sxTime=dateString
        if (this.temp==1){
          this.formData={
            ids:this.ids,
            sxTime:this.sxTime,
            date:"sx"
          }
        }else if(this.temp==2){
          this.formData={
            ids:this.ids,
            date:"dq",
            dqTime:this.sxTime,
          }
        }
      },
      add () {
        this.edit({})
      },
      edit (record) {
        this.form.resetFields()
        this.model = Object.assign({}, record)
        //this.dataSource = this.model
        this.visible = true
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model, 'docCategory', 'docName', 'docNo', 'dzDepartment', 'docSize', 'jic', 'sxTime', 'dqTime', 'isJic', 'download', 'print', 'audit', 'editorString', 'docStatus', 'docExpired'))
        })
      },
      close () {
        this.$emit('close')
        this.visible = false
      },
      handleOk () {
        const that = this;
        //修改单条记录
          putAction(this.url.batchDateUpdate, this.formData, 'put').then((res) => {
            if (res.success) {
              that.$message.success(res.message)
              that.$emit('ok')
            } else {
              that.$message.warning(res.message)
            }
          }).finally(() => {
            that.close()
          })

      },
      handleCancel () {
        this.close()
      },
      popupCallback (row) {
        this.form.setFieldsValue(pick(row, 'docCategory', 'docName', 'docNo', 'dzDepartment', 'docSize', 'jic', 'sxTime', 'dqTime', 'isJic', 'download', 'print', 'audit', 'editorString', 'docStatus', 'docExpired'))
      },


      clearForm () {
        this.form.resetFields()
        this.treeData = []
      },
    }
  }
</script>
<style scoped>
  .dateChange {
    display: flex;
    position: absolute;
  }

  .rightPart {
    left: 50px;
    bottom: 15px;
  }
</style>